/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package it.trick.admin.task;

import it.trick.admin.model.PageModel;
import it.trick.admin.model.PreModel;
import it.trick.admin.service.PreService;
import java.util.ArrayList;
import java.util.List;
import javafx.concurrent.Service;
import javafx.concurrent.Task;

/**
 *
 * @author takahara
 */
public class LoadPreListTask extends Service<List<PreModel>> {

    private PageModel pageModel;

    public void setup(PageModel pageModel) {
        this.pageModel = pageModel;
    }

    @Override
    protected Task createTask() {
        return new Task<List<PreModel>>() {
            @Override
            protected List<PreModel> call() throws Exception {

                List<PreModel> preList = new ArrayList();
                for(PreModel model: PreService.getList(pageModel.getKeyValueString())) {
                    model.setPrarentKeyString(pageModel.getKeyValueString());
                    preList.add(model);
                }

                return preList;
            }
        };
    }
}
